import 'package:dmz/base/pageWidget/base_stateful_widget.dart';
import 'package:dmz/base/widget/defult_text_field.dart';
import 'package:dmz/base/widget/defult_widget.dart';
import 'package:dmz/business/home/controller/shanre_details_controller.dart';
import 'package:dmz/business/home/model/moto_model.dart';
import 'package:dmz/business/login/widgets/login_widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class ShareDetailsWidgets {
  static Widget toWidgets(MotoModel data, String phone) {
    leftItem() {
      return Container(
          width: 330.sp,
          height: 114.sp,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(114.sp), // 设置圆角半径
              border: Border.all(
                color: Color(0xFF979797), // 设置边框颜色
                width: 2.sp, // 设置边框宽度
              )),
          child: Row(children: [
            Image.asset('assets/images/home/share/user_icon.png',
                    width: 72.sp, height: 72.sp)
                .marginOnly(right: 10.sp, left: 24.sp),
            DefaultText('本机用户'.tr, 32.sp,
                textColor: const Color(0xFFF9F9F9), fontWeight: FontWeight.w600)
          ]));
    }

    rightItem() {
      return Stack(alignment: Alignment.center, children: [
        Container(
            width: 330.sp,
            height: 114.sp,
            child: CustomPaint(
              painter: GradientCirclePainter(),
            )),
        Container(
            height: 114.sp,
            child: Row(children: [
              Image.asset('assets/images/home/share/user_icon_other.png',
                      width: 72.sp, height: 72.sp)
                  .marginOnly(left: 12.sp),
              DefaultText(phone, 32.sp, textColor: const Color(0xFFF9F9F9))
            ]))
      ]);
    }

    return Column(children: [
      DefaultText(data.name ?? '', 48.sp, textColor: Colors.white)
          .marginOnly(bottom: 48.sp),
      DefaultNetWorkImage(data.photo ?? '', width: 694.sp, height: 616.sp),
      DefaultText('将设备分享给'.tr, 32.sp, textColor: Color(0xB3FFFFFF))
          .marginOnly(bottom: 32.sp, top: 52.sp),
      Row(children: [
        leftItem(),
        Image.asset('assets/images/home/share/midle_icon.png',
                width: 128.sp, height: 128.sp)
            .marginOnly(left: 20.sp, right: 20.sp),
        rightItem()
      ]),
    ]);
  }

  static Widget bottomWidget(Function() click, Function() didShare) {
    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
      Container(
          padding: EdgeInsets.only(left: 32.sp, right: 36.sp),
          color: const Color(0xFF434650),
          height: 154.sp,
          child: Row(children: [
            DefaultText('时效选择'.tr, 40.sp,
                textColor: const Color(0xFFF9F9F9),
                fontWeight: FontWeight.w700),
            const Expanded(child: SizedBox()),
            GetBuilder<ShareDetailsController>(
                id: 'select',
                builder: (controller) {
                  return DefaultText(
                      controller.selectFirst
                          ? '不限时'.tr
                          : controller.selectDay
                              ? '${controller.inputController.text}天'
                              : '${controller.inputController.text.isEmpty ? 0 : controller.inputController.text}小时',
                      32.sp,
                      textColor: const Color(0xFFF9F9F9));
                }),
            Image.asset('assets/images/home/share/right_image.png',
                    width: 18.sp, height: 36.sp)
                .marginOnly(left: 32.sp)
          ])).addGestureDetector(click),
      DefaultText('时间从被分享人接收邀请开始计算'.tr, 32.sp,
              textColor: const Color(0xB3FFFFFF))
          .marginOnly(left: 32.sp, top: 48.sp)
          .marginOnly(bottom: 60.sp),
      Center(child: DefaultBtn(click: () => didShare(), title: '确认'.tr))
    ]).marginOnly(top: 42.sp);
  }

  static Widget shareSelectWidget(Function(bool select) timeSelect,
      Function(bool select) daySelect, Function() finished) {
    Widget selectItemWidget(String title, bool select, Function() click) {
      return Row(children: [
        Image.asset(
            'assets/images/home/share/select_${select ? 'true' : 'false'}.png',
            width: 64.sp,
            height: 64.sp),
        DefaultText(title, 40.sp, textColor: Color(0xFFF9F9F9))
      ])
          .marginOnly(bottom: 38.sp, top: 38.sp)
          .addGestureDetector(() => click());
    }

    Widget timeSelectWdiget(bool firstSelect) {
      return Container(
        decoration: BoxDecoration(
            color: const Color(0x3323C565),
            borderRadius: BorderRadius.all(Radius.circular(120.sp)),
            border: Border.all(
              color: Color(0xFF23C565), // 设置边框颜色
              width: 2.sp, // 设置边框宽度
            )),
        child: Row(mainAxisSize: MainAxisSize.min, children: [
          DefaultBtn(
              click: () => daySelect(false),
              title: '小时'.tr,
              textColor: firstSelect ? Color(0xFF23C565) : Color(0xFFF9F9F9),
              backColor: firstSelect ? Colors.transparent : null,
              width: 112.sp,
              height: 64.sp),
          DefaultBtn(
              click: () => daySelect(true),
              title: '天'.tr,
              textColor: !firstSelect ? Color(0xFF23C565) : Color(0xFFF9F9F9),
              backColor: !firstSelect ? Colors.transparent : null,
              width: 112.sp,
              height: 64.sp)
        ]),
      );
    }

    return GetBuilder<ShareDetailsController>(
        id: 'select',
        builder: (controller) {
          return widowBackWidget(
              '时效选择'.tr,
              Column(mainAxisSize: MainAxisSize.min, children: [
                selectItemWidget(
                    '不限时'.tr, controller.selectFirst, () => timeSelect(true)),
                Stack(alignment: Alignment.center, children: [
                  selectItemWidget('限时'.tr, !controller.selectFirst,
                      () => timeSelect(false)),
                  if (!controller.selectFirst)
                    Positioned(
                        right: 0, child: timeSelectWdiget(controller.selectDay))
                ]),
                if (!controller.selectFirst)
                  slelectInputWdiegt(controller.inputController),
                DefaultBtn(click: () => finished(), title: '确认'.tr)
              ]).paddingOnly(left: 32.sp, right: 32.sp, bottom: 112.sp));
        });
  }

  static slelectInputWdiegt(controlle) {
    return Center(
        child: Container(
                height: 120.sp,
                decoration: BoxDecoration(
                  color: Color(0xFF666971),
                  borderRadius: BorderRadius.all(Radius.circular(120.sp)),
                ),
                child: Row(children: [
                  Expanded(
                      child: DefultTextField(
                    32.sp,
                    hintText: '请输入数字'.tr,
                    keyboardType: TextInputType.number,
                    controlle: controlle,
                  )),
                  Image.asset('assets/images/home/share/clean_icon.png',
                      width: 48.sp, height: 48.sp)
                ]).marginOnly(left: 40.sp, right: 40.sp))
            .marginOnly(bottom: 80.sp));
  }

  static widowBackWidget(String title, Widget child, {bool hitLine = false}) {
    return Container(
        decoration: BoxDecoration(
          color: const Color(0xFF434650),
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(60.sp),
            topRight: Radius.circular(60.sp),
          ),
        ),
        child: Column(mainAxisSize: MainAxisSize.min, children: [
          Row(children: [
            DefaultText(title, 40.sp, textColor: Colors.white)
                .marginOnly(left: 32.sp),
            const Expanded(child: SizedBox()),
            Container(
                    padding: EdgeInsets.all(20.sp),
                    child: Image.asset('assets/images/home/main/close_icon.png',
                        width: 36.sp, height: 36.sp))
                .marginOnly(right: 36.sp)
          ])
              .marginOnly(top: 40.sp, bottom: 40.sp)
              .addGestureDetector(() => Get.back()),
          if (!hitLine)
            Container(
                margin: EdgeInsets.only(left: 32.sp, right: 32.sp),
                height: 2.sp,
                color: const Color(0xFFD8D8D8)),
          child
        ]));
  }
}
